package com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.pojo.PassengerOrder;
import com.pojo.vo.vo_ResponseBody;
import com.service.OrderService;

@RequestMapping("orderController")
@Controller
public class orderController {

	@Autowired
	private OrderService orderService;
	
	public orderController(){
			System.out.println("orderController 实例化");
	}
	
	@RequestMapping(value="passengerOrderPublish",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String passengerOrderPublish(String passengerOrder,Integer user_type_id){
		System.out.println(passengerOrder);
		String data="";
		PassengerOrder order;
		try {
//			passengerOrder=new String(passengerOrder.getBytes("ISO-8859-1"),"UTF-8");
			order=JSONArray.parseObject(passengerOrder, PassengerOrder.class);
			System.out.println(order);
			data=orderService.insertOnePassengerOrder(order,user_type_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		return data;
	}
	
	@RequestMapping(value="GetAllPassengerOrder",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String GetAllPassengerOrder(Integer user_Type_id){
		String data="";
		try {
			data=orderService.GetAllPassengerOrder(user_Type_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="carPool",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String carPool(Integer user_type_id,Integer here,Integer there){
		String data="";
		try {
			data=orderService.carPool(user_type_id,here,there);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="getThisCarPool",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String getThisCarPool(Integer this_users_id,Integer user_type_id){
		String data="";
		try {
			data=orderService.getThisCarPool(this_users_id,user_type_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="endOrderByUsers_id",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String endOrderByUsers_id(Integer target_users_id,Integer user_type_id,Integer this_users_id){
		String data="";
		try {
			data=orderService.endOrderByUsers_id(target_users_id,user_type_id,this_users_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="editStateToing",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String editStateToing(Integer this_user_id,Integer passengerorder_id){
		String data="";
		try {
			data=orderService.editStateToing(this_user_id,passengerorder_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="editStateToEnd",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String editStateToEnd(Integer this_user_id,Integer passengerorder_id){
		String data="";
		try {
			data=orderService.editStateToEnd(this_user_id,passengerorder_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="GetAllEndPassengerOrder",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String GetAllEndPassengerOrder(Integer user_Type_id,Integer users_id){
		String data="";
		try {
			data=orderService.GetAllEndPassengerOrder(user_Type_id,users_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(-1,0,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="getTargetUserByOrderId",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String getTargetUserByOrderId(Integer userAndPassengerOrder_id,Integer user_type_id){
		String data="";
		try {
			data=orderService.getTargetUserByOrderId(userAndPassengerOrder_id,user_type_id);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
	@RequestMapping(value="payMoney",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public String payMoney(Integer userAndPassengerOrder_id,float price){
		String data="";
		try {
			data=orderService.payMoney(userAndPassengerOrder_id,price);
		} catch (Exception e) {
			e.printStackTrace();
			data=JSONArray.toJSONString(new vo_ResponseBody(0,-1,"服务器异常"));
		}
		
		return data;
	}
	
//	@RequestMapping(value="driverPublish",produces="application/json;charset=UTF-8",method={RequestMethod.GET,RequestMethod.POST})
//	@ResponseBody
//	public String driverPublish(HttpServletRequest req){
//		
//		return orderService.insertOnePassengerOrder();
//	}
	
}
